#include "usb_can_v2.hpp"
#include <iostream>
#include <chrono>
#include <thread>

using namespace std;

void my_callback(uint16_t id, uint8_t* data, int length)
{
    std::cout << std::hex << "callback id:" << id << std::endl;
    for (int i = 0; i < length; i++)
    {
        std::cout << (int)data[i] << " ";
    }
    std::cout  << std::dec << std::endl;
}

int main()
{
    unsigned char data[7] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
    data[0] = 5000 >> 8;
    data[1] = 5000 & 0xFF;
    usb_can_v2 usb_can = usb_can_v2();
    
    usb_can.listen(0x014, my_callback);

    auto start = std::chrono::steady_clock::now();
    for (int i = 0; i < 10000; i++)
    {
        usb_can.transmit(0x1FF, data, 7);
        //std::this_thread::sleep_for(std::chrono::microseconds(10));
    }
    auto end = std::chrono::steady_clock::now();
    auto duration = end - start;
    auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
    std::cout << "finish" << ms.count() << "ms" << std::endl;
    return 0;
}